<?php
require_once '../libraries/utilites/functions.php';
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path); //doc duong dan truoc no : C://...
$films = mreadFile($path);
?>
<form method="POST">
<?php for($i = 0;$i < count($films);$i ++){
    $b= trim($films[$i],"\n\t\r ");//cat ja tri nhung dau
    $film = explode(";", $b);
    if($_GET["if"] == $film[0]){
?>
    Name :  <input type="text" name="name" size="50px"  value="<?php if(!empty($film[2])) echo $film[2]; ?>"></br>
    Rating :  <input type="text" name="rating" value="<?php if(!empty($film[3])) echo $film[3]; ?>"></br></br>
    <img width="50px" height="80px" src = '../ptnhuan-web1/public/images/films/<?php echo $film[1]; ?>'>
    <textarea rows="5" cols="50" placeholder="Chinh Sua"></textarea>
    <input type="submit" name="submit" value="Save" size="30px;">
    <a href="file.php">Back</a>
<?php }} ?>
</form>
<?php
if (isset($_POST["submit"])) {
    for ($i = 0; $i < count($films); $i++) {
        $b = trim($films[$i], " \t\n\r");
        if (!empty($b)) {
            $films[$i] = explode(";", $b);
            if ($_GET["if"] == $films[$i][0]) {
                $films[$i][2] = $_POST["name"];
                $films[$i][3] = $_POST["rating"];
            }
        } else {
            $films[$i] = $b;
        }
    }
    mwriteFile($films);
}
?>